package com.example.jianbing.juc;


import org.omg.PortableServer.THREAD_POLICY_ID;

import java.util.concurrent.CountDownLatch;

/**
 * @ClassName : CountDownLatchDemo
 * @Description :
 * @Author : JB
 * @Date: 2020-08-06 23:07
 */

/***
 *CountDownLatch主要有两个方法，当一个线程或多个线程调用await方法，这些线程会阻塞
 * 其他线程调用countDown方法会将计数器减1，（调用countDown的线程不会阻塞）
 * 当计数器的值变成0，因await方法阻塞的线程会被唤醒，继续执行
 */
public class CountDownLatchDemo {
    public static void main(String[] args) {
        CountDownLatch countDownLatch = new CountDownLatch(6);
        for (int i = 0; i <6; i++) {
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+"\t离开");
            },String.valueOf(i)).start();
        }
        countDownLatch.countDown();
        System.out.println(Thread.currentThread().getName()+"\t关门");

    }

//    public static class closeDoor(){
//
//        for (int i = 0; i < 6; i++) {
//            new Thread(()->{
//                System.out.println(Thread.currentThread().getName()+"\t离开教室");
//            },String.valueOf(i)).start();
//        }
//        System.out.println(Thread.currentThread().getName()+"\t班长关门走人");
//    }



}
